﻿@model Controller2.Models.Cidade
@{
    Layout = null;
}
<!DOCTYPE html>
<html class="no-js">
<head>
    <title>Cadastro</title>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/controller.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.vista.css").Combined(true).Compress(true)))
    <style type="text/css">
        #IdEstado
        {
            border: 1px solid #ff0000;
        }
    </style>
    @if (false)
    {
        <script src="../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../Scripts/controller.js" type="text/javascript"></script>
    }
</head>
<body id="frame">
    <div id="formHide">
        @using (Html.BeginForm())
        {
            @Html.ValidationSummary(true)
            <fieldset>
                <legend>Cidade</legend>
                @Html.HiddenFor(model => model.IdCidade)
                <div class="editor-label">
                    @Html.LabelFor(model => model.NomeCidade, "Cidade: ")
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.NomeCidade)
                    @Html.ValidationMessageFor(model => model.NomeCidade)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(model => model.IdEstado, "Estado: ")
                </div>
                <div class="editor-field">
                    @Html.DropDownListFor(model => model.IdEstado, (IEnumerable<SelectListItem>)ViewBag.Estado, "", new { style = "width: 400px;" })
                    @Html.ValidationMessageFor(model => model.IdEstado)
                </div>
            </fieldset>
        
            <div id="botoesForm">
                <input type="submit" id="Gravar" value="Gravar" />
                <input type="button" id="Fechar" value="Cancelar" />
            </div>
        }
    </div>
    <div id="alertaErro" style="display: none">
    </div>
    <script type="text/javascript">
        $(function () {
            $('#formHide').fadeIn('slow');
            hideLoading();
        });

        $('form').submit(function (e) {
            e.preventDefault();
            if ($('form').valid()) {
                $.post('@Url.Action("Salvar", "Cidade")', $('form').serialize(), function (data) {
                    $('#Gravar').attr('disabled', false);
                    if (data.salvo) {
                        closeWindow();
                    } else {
                        alertError(data.error);
                    }
                });
            }
        });

        $('#NomeCidade').blur(function (e) {
            var texto = this.value.toUpperCase();
            this.value = texto;
            e.preventDefault();
        });

        $('#Fechar').click(function () {
            closeWindow();
        });
    </script>
</body>
</html>
